
import 'package:flutter/services.dart';

import 'stripe_terminal_usb_platform_interface.dart';

class StripeTerminalUsb {
  var methodChannel =  const MethodChannel('stripe_terminal_usb');
  Function? onInitBack;
  Function? connectReadersStatusBack;
  Function? onBatteryLevelCallBack;
  Function? onBatteryWarningCallBack;

  StripeTerminalUsb(){
    methodChannel.setMethodCallHandler((call) async {
      switch (call.method) {
        case "onInit":
          await onInitBack!(call.arguments);
          break;
        case "connectReadersStatus":
          await connectReadersStatusBack!(call.arguments);
          break;
        case "onBatteryWarning":
          await onBatteryWarningCallBack!(call.arguments);
          break;
        case "onBatteryLevel":
          await onBatteryLevelCallBack!(call.arguments);
          break;
      }
    });
  }

  Future<String?> getPlatformVersion() {
    return StripeTerminalUsbPlatform.instance.getPlatformVersion();
  }

  /*
    获取权限
   */
  Future<bool> permissionAllowed() async{
    return StripeTerminalUsbPlatform.instance.permissionAllowed();
  }

  /*
  初始化 并连接读卡器
   */
  Future<void> init(String localId,String tokenUrl,String departId) async {
    await StripeTerminalUsbPlatform.instance.init(localId,tokenUrl,departId);
  }

  /*
   连接读卡器
   */
  Future<void> connectReaders() async{
    await StripeTerminalUsbPlatform.instance.connectReaders();
  }
  /*
   打开钱箱
   */
  Future<bool> initOpenCash() async{
    return StripeTerminalUsbPlatform.instance.initOpenCash();
  }
  /*
   打开钱箱
   */
  Future<Map> openCash() async{
    return StripeTerminalUsbPlatform.instance.openCash();
  }

  /*
  支付
   */
  Future<Map> pay(String clientSecret) async {
    return StripeTerminalUsbPlatform.instance.pay(clientSecret);
  }

  /*
  支付
   */
  Future<Map> processPayment() async {
    return StripeTerminalUsbPlatform.instance.processPayment();
  }

  /*
  取消等待刷卡状态
   */
  Future<bool> cancelRetrievePaymentIntent() async {
    return StripeTerminalUsbPlatform.instance.cancelRetrievePaymentIntent();
  }

  /*
  取消付款意向
   */
  Future<Map> cancelProcessPayment() async {
    return StripeTerminalUsbPlatform.instance.cancelProcessPayment();
  }
}
